﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DK.StackCalculator.Demo;
public class StackCharsMatching
{
    public Stack<char> charStack;

    public StackCharsMatching() 
    {
        charStack = new Stack<char>();
    }

    public bool IsMatching(string text) 
    {
        string str = "";
        foreach (var item in text)
        {
            if (item == '(')
            {
                charStack.Push(item);
            }
            else if (item == ')')
            {
                if (charStack.Count <= 0) return false;
                str += charStack.Pop();
            }
        }
        

        return str.Length >= 1 && charStack.Count == 0;
    }
}
